﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 员工档案增加退伍信息荣誉职称优化 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysPersonProfessionalTitle_FileAttachments_TitleDocumentId",
                table: "SysPersonProfessionalTitle");

            migrationBuilder.DropColumn(
                name: "TitleLevel",
                table: "SysPersonProfessionalTitle");

            migrationBuilder.DropColumn(
                name: "Age",
                table: "SysPerson");

            migrationBuilder.RenameColumn(
                name: "TitleName",
                table: "SysPersonProfessionalTitle",
                newName: "QualificationName");

            migrationBuilder.RenameColumn(
                name: "TitleDocumentId",
                table: "SysPersonProfessionalTitle",
                newName: "CertificateDocumentId");

            migrationBuilder.RenameIndex(
                name: "IX_SysPersonProfessionalTitle_TitleDocumentId",
                table: "SysPersonProfessionalTitle",
                newName: "IX_SysPersonProfessionalTitle_CertificateDocumentId");

            migrationBuilder.AddColumn<DateTime>(
                name: "ExpiryDate",
                table: "SysPersonProfessionalTitle",
                type: "datetime2",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "IssuingAuthority",
                table: "SysPersonProfessionalTitle",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "ObtainedDate",
                table: "SysPersonProfessionalTitle",
                type: "datetime2",
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "ProfessionalTitleTypeId",
                table: "SysPersonProfessionalTitle",
                type: "uniqueidentifier",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.AddColumn<int>(
                name: "QualificationLevel",
                table: "SysPersonProfessionalTitle",
                type: "int",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Remark",
                table: "SysPersonProfessionalTitle",
                type: "nvarchar(500)",
                maxLength: 500,
                nullable: true);

            migrationBuilder.AddColumn<bool>(
                name: "IsVeteran",
                table: "SysPerson",
                type: "bit",
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "VeteranCertificateId",
                table: "SysPerson",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "SysPersonProfessionalTitleType",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CategoryCode = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    CategoryName = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    SortOrder = table.Column<int>(type: "int", nullable: true),
                    Remark = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPersonProfessionalTitleType", x => x.ID);
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysPersonProfessionalTitle_ProfessionalTitleTypeId",
                table: "SysPersonProfessionalTitle",
                column: "ProfessionalTitleTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPerson_VeteranCertificateId",
                table: "SysPerson",
                column: "VeteranCertificateId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysPerson_FileAttachments_VeteranCertificateId",
                table: "SysPerson",
                column: "VeteranCertificateId",
                principalTable: "FileAttachments",
                principalColumn: "ID",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_SysPersonProfessionalTitle_FileAttachments_CertificateDocumentId",
                table: "SysPersonProfessionalTitle",
                column: "CertificateDocumentId",
                principalTable: "FileAttachments",
                principalColumn: "ID",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_SysPersonProfessionalTitle_SysPersonProfessionalTitleType_ProfessionalTitleTypeId",
                table: "SysPersonProfessionalTitle",
                column: "ProfessionalTitleTypeId",
                principalTable: "SysPersonProfessionalTitleType",
                principalColumn: "ID",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysPerson_FileAttachments_VeteranCertificateId",
                table: "SysPerson");

            migrationBuilder.DropForeignKey(
                name: "FK_SysPersonProfessionalTitle_FileAttachments_CertificateDocumentId",
                table: "SysPersonProfessionalTitle");

            migrationBuilder.DropForeignKey(
                name: "FK_SysPersonProfessionalTitle_SysPersonProfessionalTitleType_ProfessionalTitleTypeId",
                table: "SysPersonProfessionalTitle");

            migrationBuilder.DropTable(
                name: "SysPersonProfessionalTitleType");

            migrationBuilder.DropIndex(
                name: "IX_SysPersonProfessionalTitle_ProfessionalTitleTypeId",
                table: "SysPersonProfessionalTitle");

            migrationBuilder.DropIndex(
                name: "IX_SysPerson_VeteranCertificateId",
                table: "SysPerson");

            migrationBuilder.DropColumn(
                name: "ExpiryDate",
                table: "SysPersonProfessionalTitle");

            migrationBuilder.DropColumn(
                name: "IssuingAuthority",
                table: "SysPersonProfessionalTitle");

            migrationBuilder.DropColumn(
                name: "ObtainedDate",
                table: "SysPersonProfessionalTitle");

            migrationBuilder.DropColumn(
                name: "ProfessionalTitleTypeId",
                table: "SysPersonProfessionalTitle");

            migrationBuilder.DropColumn(
                name: "QualificationLevel",
                table: "SysPersonProfessionalTitle");

            migrationBuilder.DropColumn(
                name: "Remark",
                table: "SysPersonProfessionalTitle");

            migrationBuilder.DropColumn(
                name: "IsVeteran",
                table: "SysPerson");

            migrationBuilder.DropColumn(
                name: "VeteranCertificateId",
                table: "SysPerson");

            migrationBuilder.RenameColumn(
                name: "QualificationName",
                table: "SysPersonProfessionalTitle",
                newName: "TitleName");

            migrationBuilder.RenameColumn(
                name: "CertificateDocumentId",
                table: "SysPersonProfessionalTitle",
                newName: "TitleDocumentId");

            migrationBuilder.RenameIndex(
                name: "IX_SysPersonProfessionalTitle_CertificateDocumentId",
                table: "SysPersonProfessionalTitle",
                newName: "IX_SysPersonProfessionalTitle_TitleDocumentId");

            migrationBuilder.AddColumn<string>(
                name: "TitleLevel",
                table: "SysPersonProfessionalTitle",
                type: "nvarchar(64)",
                maxLength: 64,
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Age",
                table: "SysPerson",
                type: "int",
                nullable: true);

            migrationBuilder.AddForeignKey(
                name: "FK_SysPersonProfessionalTitle_FileAttachments_TitleDocumentId",
                table: "SysPersonProfessionalTitle",
                column: "TitleDocumentId",
                principalTable: "FileAttachments",
                principalColumn: "ID",
                onDelete: ReferentialAction.Restrict);
        }
    }
}
